package com.example.permissionsystem1_1.businessFunction.controller.impl;

import com.example.permissionsystem1_1.businessFunction.controller.converter.DepartmentUserControllerConverter;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.departmentUserReqDto.DepartmentUserSelectAllDepartmentsByUserIdReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.departmentUserReqDto.DepartmentUserSetDepartmentUserRelationReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.departmentUserRspDto.DepartmentUserSelectAllDepartmentsByUserIdRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.departmentUserRspDto.DepartmentUserSetDepartmentUserRelationRspDto;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.departmentUserReqModel.DepartmentUserSelectAllDepartmentsByUserIdReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.departmentUserReqModel.DepartmentUserSetDepartmentUserRelationReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentUserRspModel.DepartmentUserSelectAllDepartmentsByUserIdRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentUserRspModel.DepartmentUserSetDepartmentUserRelationRspModel;
import com.example.permissionsystem1_1.businessFunction.service.interfaces.DepartmentUserService;
import com.example.permissionsystem1_1.common.businessFunction.BaseController;
import com.example.permissionsystem1_1.common.util.RspResult;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 部门-用户类
 * 后面这里的基础接口方法,都应该抽取成公共方法放到Base类中或者是用代码生成器生成模板代码(而不需要手写)
 */
@RestController
@RequestMapping("/departmentUser")
@ApiModel("部门-用户")
public class DepartmentUserController extends BaseController {
    @Autowired
    private DepartmentUserService departmentUserService;

    @ApiOperation(value = "根据用户id查询全部部门信息", notes = "根据用户id查询全部部门信息", httpMethod = "POST")
    @RequestMapping(value = "/selectAllDepartmentsByUserId",method = RequestMethod.POST)
    public RspResult<DepartmentUserSelectAllDepartmentsByUserIdRspDto> selectAllDepartmentsByUserId(@Validated @RequestBody DepartmentUserSelectAllDepartmentsByUserIdReqDto reqDto){
        DepartmentUserSelectAllDepartmentsByUserIdReqModel reqModel= DepartmentUserControllerConverter.convertDtoToModel(reqDto);
        DepartmentUserSelectAllDepartmentsByUserIdRspModel rspModel=departmentUserService.selectAllDepartmentsByUserId(reqModel);
        DepartmentUserSelectAllDepartmentsByUserIdRspDto rspDto=DepartmentUserControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "设置部门与用户的关联关系", notes = "设置部门与用户的关联关系", httpMethod = "POST")
    @RequestMapping(value = "/setDepartmentUserRelation",method = RequestMethod.POST)
    public RspResult<DepartmentUserSetDepartmentUserRelationRspDto> setDepartmentUserRelation(@Validated @RequestBody DepartmentUserSetDepartmentUserRelationReqDto reqDto){
        DepartmentUserSetDepartmentUserRelationReqModel reqModel= DepartmentUserControllerConverter.convertDtoToModel(reqDto);
        DepartmentUserSetDepartmentUserRelationRspModel rspModel=departmentUserService.setDepartmentUserRelation(reqModel);
        DepartmentUserSetDepartmentUserRelationRspDto rspDto=DepartmentUserControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }


}
